Test operates correctly regardless of dev's ENV config

Will Read 9 years ago
parent
commit
b87ac1d6d4
1 changed files with 24 additions and 13 deletions
  1. 24 13
      spec/models/users_spec.rb

+ 24 - 13
spec/models/users_spec.rb

@@ -3,22 +3,33 @@ require 'spec_helper'
3 3
 describe User do
4 4
   describe "validations" do
5 5
     describe "invitation_code" do
6
-      it "only accepts valid invitation codes" do
7
-        User::INVITATION_CODES.each do |v|
8
-          is_expected.to allow_value(v).for(:invitation_code)
6
+      context "when configured to use invitation codes" do
7
+        before do
8
+          stub(User).using_invitation_code? {true}
9 9
         end
10
-      end
11
-
12
-      it "can reject invalid invitation codes" do
13
-        %w['foo', 'bar'].each do |v|
14
-          is_expected.not_to allow_value(v).for(:invitation_code)
10
+        
11
+        it "only accepts valid invitation codes" do
12
+          User::INVITATION_CODES.each do |v|
13
+            is_expected.to allow_value(v).for(:invitation_code)
14
+          end
15
+        end
16
+  
17
+        it "can reject invalid invitation codes" do
18
+          %w['foo', 'bar'].each do |v|
19
+            is_expected.not_to allow_value(v).for(:invitation_code)
20
+          end
15 21
         end
16 22
       end
17
-
18
-      it "skips this validation if configured to do so" do
19
-        stub(User).using_invitation_code? {false}
20
-        %w['foo', 'bar', nil, ''].each do |v|
21
-          is_expected.to allow_value(v).for(:invitation_code)
23
+      
24
+      context "when configured not to use invitation codes" do
25
+        before do
26
+          stub(User).using_invitation_code? {false}
27
+        end
28
+        
29
+        it "skips this validation" do
30
+          %w['foo', 'bar', nil, ''].each do |v|
31
+            is_expected.to allow_value(v).for(:invitation_code)
32
+          end
22 33
         end
23 34
       end
24 35
     end